<?php

namespace App\Http\Controllers\Teaching;

use App\Common\Utils\JsonResponse;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ActivityController extends Controller
{
    /** @var \App\Services\System\LogService $logService */
    private $logService;
    /** @var \App\Services\Teaching\ActivityService $activityService */
    private $activityService;

    /**
    * Create a new controller instance.
    *
    * @return void
    */
    public function __construct()
    {
        parent::__construct();
        // $this->middleware('auth');
        $this->logService = app('logService');
        $this->activityService = app('tactivityService');
    }

    /**
     * @Description: 获取教研活动列表信息数据
     * @Author: kzj
     * @datetime: 2023-03-16
     */
    public function getList(Request $request)
    {
        try
        {
            $result = $this->activityService->getList($request->all());
            $this->logService->log('246', '教研活动查看', '教研活动查看');
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 教研活动添加
     * @Author: kzj
     * @datetime: 2023-03-16
     */
    public function add(Request $request)
    {
        try{
            $result = $this->activityService->add($request->all());
            $this->logService->log('247', '教研活动添加', '教研活动添加');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 教研活动添加作业
     * @Author: kzj
     * @datetime: 2023-03-16
     */
    public function addHomework(Request $request)
    {
        try{
            $result = $this->activityService->addHomework($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 教研活动单条数据
     * @Author: kzj
     * @datetime: 2023-03-16
     */
    public function one(Request $request)
    {
        try{
            $result = $this->activityService->one($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 教研活动编辑
     * @Author: kzj
     * @datetime: 2023-03-16
     */
    public function edit(Request $request)
    {
        try{
            $result = $this->activityService->edit($request->all());
            $this->logService->log('248', '教研活动编辑', '教研活动编辑');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 教研活动删除
     * @Author: kzj
     * @datetime: 2023-03-16
     */
    public function del(Request $request)
    {
        try{
            $result = $this->activityService->del($request->all());
            $this->logService->log('250', '教研活动删除', '教研活动删除');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 教研活动文件下载
     * @Author: kzj
     * @datetime: 2023-03-28
     */
    public function download(Request $request)
    {
        try{
            $result = $this->activityService->download($request->all());
            $this->logService->log('253', '教研活动文件下载', '教研活动文件下载');
            return JsonResponse::success($result, '操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 教研活动删除作业
     * @Author: kzj
     * @datetime: 2023-03-16
     */
    public function delHomework(Request $request)
    {
        try{
            $result = $this->activityService->delHomework($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 作业数据
     * @Author: kzj
     * @datetime: 2023-03-23
     */
    public function getHomeworkInfo(Request $request)
    {
        try{
            $result = $this->activityService->getHomeworkInfo($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 作业提交
     * @Author: kzj
     * @datetime: 2023-03-23
     */
    public function saveHomework(Request $request)
    {
        try{
            $result = $this->activityService->saveHomework($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 添加评论
     * @Author: kzj
     * @datetime: 2023-03-23
     */
    public function addComment(Request $request)
    {
        try{
            $result = $this->activityService->addComment($request->all());
            return JsonResponse::success($result, '评论成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 获取二维码
     * @Author: kzj
     * @datetime: 2023-03-24
     */
    public function getQRCode(Request $request)
    {
        try{
            $result = $this->activityService->getQRCode($request->all());
            return JsonResponse::success($result);
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 签到
     * @Author: kzj
     * @datetime: 2023-03-27
     */
    public function addActivitySign(Request $request)
    {
        try{
            $result = $this->activityService->addSign($request->all());
            return JsonResponse::success($result, '签到成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 活动参与进度数据
     * @Author: kzj
     * @datetime: 2023-03-27
     */
    public function getJoinList(Request $request)
    {
        try
        {
            $result = $this->activityService->getJoinList($request->all());
            return JsonResponse::success($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 活动参与进度数据导出
     * @Author: kzj
     * @datetime: 2023-03-27
     */
    public function export(Request $request)
    {
        try{
            $result = $this->activityService->export($request->all());
            $this->logService->log('254', '教研活动参与进度数据导出', '教研活动参与进度数据导出');
            return JsonResponse::success($result, '操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 教师个人作业文件下载
     * @Author: kzj
     * @datetime: 2023-03-28
     */
    public function downloadHomework(Request $request)
    {
        try{
            $result = $this->activityService->downloadHomework($request->all());
            $this->logService->log('253', '教研活动教师个人作业文件下载', '教研活动教师个人作业文件下载');
            return JsonResponse::success($result, '操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 列表数据导出
     * @Author: kzj
     * @datetime: 2023-11-27
     */
    public function exportTeaActivity(Request $request)
    {
        try{
            $result = $this->activityService->exportTeaActivity($request->all());
            $this->logService->log('254', '教研活动列表数据导出', '教研活动列表数据导出');
            return JsonResponse::success($result, '操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /*
     * @Description: 生成证明单
     * @Author:  Kzj
     * @Date: 2024-01-30 15:23:16
     */
    public function generateCertificate(Request $request)
    {
        try{
            $result = $this->activityService->generateCertificate($request->all());
            return JsonResponse::success($result, '操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    public function push(Request $request)
    {
        try{
            $result = $this->activityService->push($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }
}
